﻿using System;
using System.Collections.Generic;
using Money.Plugins;

namespace Money.Plugins.Import
{
    public class ImportHandlers
    {
        public List<IPluginImport> Handlers { get; set; }

        public ImportHandlers()
        {
            Handlers = new List<IPluginImport>();
            DetectHandlers();
        }

        private void DetectHandlers()
        {
            // TODO we can probably refactor this out now that plugin framework is implemented
            foreach (IPluginImport importHandler in PluginHost.ImportPlugins)
            {
                Handlers.Add(importHandler);
            }
        }

        public IPluginImport GetHandler(string parser)
        {
            foreach (IPluginImport ih in Handlers)
            {
                if (ih.Name == parser)
                {
                    return ih;
                }
            }

            return null;
        }

        public IEnumerable<string> GetHandlers()
        {
            foreach (IPluginImport ih in Handlers)
            {
                yield return ih.Name;
            }
        }
    }
}
